﻿using System;
using System.Collections.Generic;
using Framework;

namespace Enterprise.Admin.Handle
{
    public partial class GetPagesListJson : AdminBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var datas = new List<object>();
            var title = Fq("CoTitle").SafeToString();
            var columnId = Fq("CoColumnId").SafeToInt();
            var language = Fq("CoLanguage").SafeToString();
            var pageValue = Fq("page").SafeToInt();
            var rowsValue = Fq("rows").SafeToInt();
            var pageService = new PageService();
            var table = pageService.GetTable(title, columnId, language, pageValue, rowsValue);
            object result = new { total = table.Total, rows = datas };
            for (int i = 0; i < table.Rows.Count; i++)
            {
                datas.Add(new
                {
                    id = table.Rows[i]["CoPageId"].SafeToInt(),
                    CoTitle = table.Rows[i]["CoTitle"].SafeToString(),
                    CoKeyName = table.Rows[i]["CoKeyName"].SafeToString(),
                    CoPath = table.Rows[i]["CoPath"].SafeToString(),
                    CoColumnId = table.Rows[i]["CoColumnId"].SafeToInt(),
                    CoIsRecommend = table.Rows[i]["CoIsRecommend"].SafeToBool(),
                    CoIsPopular = table.Rows[i]["CoIsPopular"].SafeToBool(),
                    CoIsTop = table.Rows[i]["CoIsTop"].SafeToBool(),
                    CoViews = table.Rows[i]["CoViews"].SafeToInt(),
                    CoAuthor = table.Rows[i]["CoAuthor"].SafeToString(),
                    CoDate = table.Rows[i]["CoDate"].SafeToDateTime(),
                    CoIsReserved = table.Rows[i]["CoIsReserved"].SafeToBool(),
                    CoReservedUrl = table.Rows[i]["CoReservedUrl"].SafeToString(),
                    CoColumnName = table.Rows[i]["CoColumnName"].SafeToString(),
                    CoLanguage = table.Rows[i]["CoLanguage"].SafeToString(),
                });
            }
            Json(result);
        }
    }
}